package myBean;

import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.RequestDispatcher;

/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */
/**
 *
 * @author Huong
 */
public class User {

    private String name;
    private String password;

    public User() {
    }

    public String getName() {
        return name;
    }

    public String getPassword() {
        return password;
    }

    public boolean available() {
        try {
            //db
            String connectionUrl = "jdbc:sqlserver://localhost:1433;databaseName=CategoryDB;user=sa;password=sa";
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            Connection con = DriverManager.getConnection(connectionUrl);

            String selectQ = "SELECT * FROM UserDB";
            PreparedStatement selectSt = con.prepareStatement(selectQ);
            ResultSet rs = selectSt.executeQuery(selectQ);


            while (rs.next()) {

                if (name.equalsIgnoreCase(rs.getString("User")) && password.equalsIgnoreCase(rs.getString("Password"))) {
                    return true;
                }
            }
        } catch (ClassNotFoundException ex) {
        } catch (SQLException ex) {
        }
        return false;

    }

    
}
